package first.group.ssh.gui.frame;

import first.group.ssh.gui.model.MainModel;
import javax.swing.Box;
import javax.swing.Box.Filler;

public class MainFrame extends javax.swing.JFrame {
    private final MainModel model;
    
    public MainFrame() {
        this(new MainModel());
    }
    
    @SuppressWarnings("LeakingThisInConstructor")
    public MainFrame(MainModel model) {
        initComponents();
        this.model = model;
        model.bindToFrame(this);
        setLocationRelativeTo(null);
    }
    
    @Override
    public void dispose() {
        super.dispose();
        model.dispose();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        centerPanel = new javax.swing.JPanel();
        connectPanel = new javax.swing.JPanel();
        connectLabel = new javax.swing.JLabel();
        connectPanelSpacing = (Filler) Box.createVerticalStrut(8);
        connectButton = new javax.swing.JButton();
        connectionsPane = new javax.swing.JTabbedPane();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        connectItem = new javax.swing.JMenuItem();
        fileMenuSpearator = new javax.swing.JPopupMenu.Separator();
        exitItem = new javax.swing.JMenuItem();
        connectionMenu = new javax.swing.JMenu();
        disconnectItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SSH 连接");
        setMinimumSize(new java.awt.Dimension(400, 300));
        setPreferredSize(new java.awt.Dimension(500, 400));

        mainPanel.setLayout(new javax.swing.OverlayLayout(mainPanel));

        centerPanel.setLayout(new javax.swing.BoxLayout(centerPanel, javax.swing.BoxLayout.LINE_AXIS));

        connectPanel.setLayout(new javax.swing.BoxLayout(connectPanel, javax.swing.BoxLayout.Y_AXIS));

        connectLabel.setText("目前暂无连接");
        connectLabel.setToolTipText("");
        connectLabel.setAlignmentX(0.5F);
        connectLabel.setAlignmentY(0.0F);
        connectPanel.add(connectLabel);
        connectPanel.add(connectPanelSpacing);

        connectButton.setText("连接到服务器");
        connectButton.setAlignmentX(0.5F);
        connectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectButtonActionPerformed(evt);
            }
        });
        connectPanel.add(connectButton);

        centerPanel.add(connectPanel);

        mainPanel.add(centerPanel);
        mainPanel.add(connectionsPane);

        getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);

        fileMenu.setText("文件");

        connectItem.setText("连接到服务器");
        connectItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectItemActionPerformed(evt);
            }
        });
        fileMenu.add(connectItem);
        fileMenu.add(fileMenuSpearator);

        exitItem.setText("退出");
        exitItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitItem);

        menuBar.add(fileMenu);

        connectionMenu.setText("连接");

        disconnectItem.setText("断开");
        disconnectItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                disconnectItemActionPerformed(evt);
            }
        });
        connectionMenu.add(disconnectItem);

        menuBar.add(connectionMenu);

        helpMenu.setText("帮助");

        aboutItem.setText("关于");
        aboutItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void aboutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutItemActionPerformed
        model.openAboutDialog();
    }//GEN-LAST:event_aboutItemActionPerformed

    private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed
        model.openConnectDialog();
    }//GEN-LAST:event_connectButtonActionPerformed

    private void connectItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectItemActionPerformed
        model.openConnectDialog();
    }//GEN-LAST:event_connectItemActionPerformed

    private void exitItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitItemActionPerformed
        model.exit();
    }//GEN-LAST:event_exitItemActionPerformed

    private void disconnectItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disconnectItemActionPerformed
        model.disconnect();
    }//GEN-LAST:event_disconnectItemActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JMenuItem aboutItem;
    public javax.swing.JPanel centerPanel;
    public javax.swing.JButton connectButton;
    public javax.swing.JMenuItem connectItem;
    public javax.swing.JLabel connectLabel;
    private javax.swing.JPanel connectPanel;
    private javax.swing.Box.Filler connectPanelSpacing;
    private javax.swing.JMenu connectionMenu;
    public javax.swing.JTabbedPane connectionsPane;
    public javax.swing.JMenuItem disconnectItem;
    public javax.swing.JMenuItem exitItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JPopupMenu.Separator fileMenuSpearator;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables
}
